<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>牛马新闻中心</title>
    <link rel="stylesheet" type="text/css" href="./CSS/Index.css"/>
<!--    <script type="text/javascript" src="JS/Walk_robot.js"  defer="defer"></script>-->
<!--    <style type="text/css">-->
<!--        canvas {-->
<!--            position: absolute;-->
<!--            width: 100%;-->
<!--            height: 100%;-->
<!--            cursor: pointer;-->
<!--        }-->
<!--    </style>-->
</head>
<body>

<!--<%@ include file="Header.jsp" %>-->
<div class="re">
    <ul>
        <li><img src="IMGS/03.jpeg" width="100%" alt="图片"></li>
        <li><img src="IMGS/04.png" width="100%" alt="图片"></li>
        <li><img src="IMGS/05.png" width="100%" alt="图片"></li>
        <li><img src="IMGS/06.png" width="100%" alt="图片"></li>
    </ul>
</div>
<div class="Recent_news">
    <span>近期新闻</span><span style="float: right;cursor: pointer">更多...</span><br/>
    <div class="Recent_news_news" id="Recent_news_news">
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
    </div>
</div>

</body>
<script type="text/javascript">
    var NTitle = document.getElementsByClassName('News_title');
    for(var i=0;i<5;i++){
        NTitle[i].onclick=function () {
            this.style.color='red';
        }
        NTitle[i].onmouseout=function () {
            this.style.color='blue';
        }
    }
</script>
<!--更改字体颜色-->
<script type="text/javascript">
    var box=this.document.getElementsByClassName("re")[0];
    var lik=box.getElementsByTagName("li");
    function fun(i,j) {
        lik[i].style.opacity=1;
        lik[j].style.opacity=0;
    }
    fun(0,1);
    var i =0;
    function auto() {
        if(++i>=4) {
            i=0;
            fun(0,3);
        } else fun(i,i-1);
    }
    var timer=this.setInterval(auto,5000);
    box.onmouseover = function ()
    {
        clearInterval(timer);
    }
    box.onmouseout=function()
    {
        timer = setInterval(auto, 5000);
    }
</script>
<!--轮播图-->
<script type="text/javascript">
    function ajaxFunction() {
        var xmlHttp;
        try { // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {// Internet Explorer
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        }
        return xmlHttp;
    }
    // 创建AJAX
    function Onloading() {
        var sql="Select * from newsdetail";
        var request = ajaxFunction();
        // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
        request.open("POST", "MSG", true);			//全部新闻
        // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
        request.onreadystatechange = function() {
            //前半段表示 已经能够正常处理。  再判断状态码是否是200
            if (request.readyState == 4 && request.status == 200) {
                //弹出响应的信息
                var test = eval("("+request.responseText+")");
                var news ="";
                for(var i=0;i<5;i++){
                    news+='<span class="News_title" onclick="GO(this)">'+test[i].title+'</span><span class="Recent_news_right">'+test[i].time+'</span><br/>';
                }
                document.getElementById("Recent_news_news").innerHTML=news;
            }
        }
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.send("sql="+sql);
    }
    Onloading();
</script>
<!--获取数据-->
<script type="text/javascript">
    function GO(nT) {
        var rs = /<span class="News_title">(.*?)<\/span>/;
        var inner=nT.innerHTML.match(rs);
        window.localStorage.setItem("newstitle",inner[1]);
        window.location="#";
    }
</script>
<!--新闻标题点击事件-->
<script type="text/javascript">
    function CheckLogin() {
        var Uname = window.localStorage.getItem("Uname");
        var Uid = window.localStorage.getItem("Uid");
        if (Uname!=null&&Uid!=null){
            console.log("已登录");
            document.getElementsByClassName("unLogin")[0].style.display="none";
            document.getElementsByClassName("unLogin")[1].style.display="none";
            document.getElementsByClassName("Logining")[0].style.display="block";
            document.getElementsByClassName("Logining")[1].style.display="block";
        }else {
            console.log("未登录");
            document.getElementsByClassName("unLogin")[0].style.display="block";
            document.getElementsByClassName("unLogin")[1].style.display="block";
            document.getElementsByClassName("Logining")[0].style.display="none";
            document.getElementsByClassName("Logining")[1].style.display="none";
        }
    }
    CheckLogin();
</script>
<!--检查登录态-->
</html>